package com.wao.cms.domain;

import com.wao.base.domain.BaseMultitenantAuditingEntity;
import io.swagger.annotations.ApiModel;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Objects;

/**
 * PropertyValue entity.
 *
 * @author Arthur.
 */
@ApiModel(description = "PropertyValue entity. @author Arthur.")
@Entity
@Table(name = "cms_property_value")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PropertyValue extends BaseMultitenantAuditingEntity {

    private static final long serialVersionUID = 1L;

    @Lob
    @Column(name = "jhi_value")
    private String value;

    @Size(max = 8)
    @Column(name = "lang_key", length = 8)
    private String langKey;

    @ManyToOne(optional = false)
    @NotNull
    private Page page;

    @ManyToOne(optional = false)
    @NotNull
    private TemplateProperty property;

    @ManyToOne
    private Material material;

    public String getValue() {
        return value;
    }

    public PropertyValue value(String value) {
        this.value = value;
        return this;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLangKey() {
        return langKey;
    }

    public PropertyValue langKey(String langKey) {
        this.langKey = langKey;
        return this;
    }

    public void setLangKey(String langKey) {
        this.langKey = langKey;
    }

    public Page getPage() {
        return page;
    }

    public PropertyValue page(Page page) {
        this.page = page;
        return this;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public TemplateProperty getProperty() {
        return property;
    }

    public PropertyValue property(TemplateProperty templateProperty) {
        this.property = templateProperty;
        return this;
    }

    public void setProperty(TemplateProperty templateProperty) {
        this.property = templateProperty;
    }

    public Material getMaterial() {
        return material;
    }

    public PropertyValue material(Material material) {
        this.material = material;
        return this;
    }

    public void setMaterial(Material material) {
        this.material = material;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        PropertyValue propertyValue = (PropertyValue) o;
        if (propertyValue.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), propertyValue.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "PropertyValue{" +
            "id=" + getId() +
            ", value='" + getValue() + "'" +
            ", langKey='" + getLangKey() + "'" +
            "}";
    }
}
